package com.itheima.api.sms;

import com.alibaba.dubbo.config.annotation.Service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.mapper.sms.SmsFlashPromotionMapper;
import com.itheima.vo.domain.TableDataInfo;
import com.itheima.vo.pojo.SmsFlashPromotion;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

@Service
public class SmsFlashPromotionServiceImpl extends ServiceImpl<SmsFlashPromotionMapper, SmsFlashPromotion> implements SmsFlashPromotionService{

    @Autowired
    private SmsFlashPromotionMapper smsFlashPromotionMapper;


    @Override
    public TableDataInfo page(Integer pageNum, Integer pageSize, String keyword) {
        Page<SmsFlashPromotion> pageInfo = new Page<>(pageNum,pageSize);
        TableDataInfo tableDataInfo = new TableDataInfo();
        LambdaQueryWrapper<SmsFlashPromotion> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(StringUtils.isNotEmpty(keyword),SmsFlashPromotion::getTitle,keyword);

        smsFlashPromotionMapper.selectPage(pageInfo,queryWrapper);

        tableDataInfo.setList(pageInfo.getRecords());
        tableDataInfo.setPageNum(pageNum);
        tableDataInfo.setPageSize(pageSize);
        tableDataInfo.setTotal(pageInfo.getTotal());
        tableDataInfo.setTotalPage(pageInfo.getPages());

        return tableDataInfo;
    }

    @Override
    public void update(SmsFlashPromotion smsFlashPromotion) {
        smsFlashPromotionMapper.update(smsFlashPromotion);
    }

    @Override
    public void updateStatus(SmsFlashPromotion smsFlashPromotion) {
        smsFlashPromotionMapper.updateStatus(smsFlashPromotion);
    }
}
